
<template>
    <!-- 添加或修改设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false"
        v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="环保设备" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="购买厂家" prop="supplier" required>
                                <el-input v-model="form.supplier" placeholder="请输入购买厂家" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备名称" prop="name" required>
                                <el-input v-model="form.name" placeholder="请输入设备名称" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备编码" prop="code" required>
                                <el-input v-model="form.code" placeholder="请输入设备编码" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备品牌" prop="pinpai">
                                <el-input v-model="form.pinpai" placeholder="请输入设备品牌" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="型号" prop="xinghao">
                                <el-input v-model="form.xinghao" placeholder="请输入型号" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="购买日期" prop="buyDate">
                                <el-date-picker clearable v-model="form.buyDate" type="date" value-format="yyyy-MM-dd"
                                    placeholder="请选择购买日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="存放位置" prop="addr">
                                <el-input v-model="form.addr" placeholder="请输入存放位置" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产能" prop="channeng">
                                <el-input v-model="form.channeng" placeholder="请输入产能" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备发票" prop="fapiao">
                                <file-upload v-model="form.fapiao" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备合同" prop="hetong">
                                <file-upload v-model="form.hetong" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="检定证书" prop="baogao">
                                <file-upload v-model="form.baogao" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备单价" prop="money">
                                <el-input-number v-model="form.money" placeholder="请输入设备单价" />元
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备数量" prop="counts">
                                <el-input-number v-model="form.counts" placeholder="请输入设备数量" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备总价" prop="allmoney">
                                <el-input-number v-model="form.allmoney" placeholder="请输入设备总价" />元
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="审核人" prop="shenheName">
                                <el-input v-model="form.shenheName" placeholder="请输入审核人" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="经办人" prop="usename">
                                <el-input v-model="form.usename" placeholder="请输入经办人" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备类型" prop="type">
                                <el-select v-model="form.type" placeholder="请选择设备类型" clearable style="width: 80%;">
                                    <el-option v-for="dict in dict.type.shebei_type"
                                        :key="dict.value" :label="dict.label" :value="dict.value"/>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="所属车间" prop="haveHouse">
                                <el-input v-model="form.haveHouse" placeholder="请输入所属车间" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="备注" prop="remark">
                                <el-input v-model="form.remark" placeholder="请输入备注" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane label="车间维修" name="second">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="维修保养类型" prop="repairType">
                                <el-input v-model="form.repairType" placeholder="请输入维修保养类型" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备编号" prop="deviceNumber">
                                <el-input v-model="form.deviceNumber" placeholder="请输入设备编号" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备名称" prop="deviceName">
                                <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备型号" prop="deviceModel">
                                <el-input v-model="form.deviceModel" placeholder="请输入设备型号" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="所属车间" prop="workshop">
                                <el-input v-model="form.workshop" placeholder="请输入所属车间" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="使用部门" prop="useDepartment">
                                <el-input v-model="form.useDepartment" placeholder="请输入使用部门" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="检修申请人" prop="applicant">
                                <el-input v-model="form.applicant" placeholder="请输入检修申请人" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="故障问题" prop="faultProblem">
                                <el-input v-model="form.faultProblem" placeholder="请输入故障问题" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="故障类别" prop="faultCategory">
                                <el-input v-model="form.faultCategory" placeholder="请输入故障类别" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane label="车间保养" name="third">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="维修/保养内容" prop="maintenanceContent">
                                <el-input v-model="form.maintenanceContent" placeholder="请输入维修/保养内容" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="点检内容" prop="inspectionContent">
                                <el-input v-model="form.inspectionContent" placeholder="请输入点检内容" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维修/保养金额" prop="maintenanceAmount">
                                <el-input v-model="form.maintenanceAmount" placeholder="请输入维修/保养金额" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维修/保养时间" prop="maintenanceTime">
                                <el-input v-model="form.maintenanceTime" placeholder="请输入维修/保养时间" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维修保养记录" prop="maintenanceRecord">
                                <el-input v-model="form.maintenanceRecord" placeholder="请输入维修保养记录" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维修/保养人" prop="maintenancePerson">
                                <el-input v-model="form.maintenancePerson" placeholder="请输入维修/保养人" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="点检人" prop="inspectionPerson">
                                <el-input v-model="form.inspectionPerson" placeholder="请输入点检人" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="验收人" prop="acceptancePerson">
                                <el-input v-model="form.acceptancePerson" placeholder="请输入验收人" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane label="试验设备" name="fourth">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="更换配件" prop="replacementParts">
                                <el-input v-model="form.replacementParts" placeholder="请输入更换配件" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="配件费" prop="partsFee">
                                <el-input v-model="form.partsFee" placeholder="请输入配件费" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合计" prop="total">
                                <el-input v-model="form.total" placeholder="请输入合计" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="车间主任" prop="workshopManager">
                                <el-input v-model="form.workshopManager" placeholder="请输入车间主任" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="主管领导" prop="leader">
                                <el-input v-model="form.leader" placeholder="请输入主管领导" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { addAction, getById, updateAction } from '@/api/manage';
export default {
        name: "maintenanceForm",
    dicts: ['shebei_type'],
    data() {
        return {
            // 遮罩层
            loading: true,
            activeName: "first",
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 表单参数
            form: {},
            url: {
                getById: '/lnShebei/lnShebei/',
                add: '/lnShebei/lnShebei/add',
                edit: '/lnShebei/lnShebei/edit',
            },
            rules: {
                // 更新规则以匹配新表单结构
                supplier: [
                    { required: true, message: '请输入购买厂家', trigger: 'blur' }
                ],
                name: [
                    { required: true, message: '请输入设备名称', trigger: 'blur' }
                ],
                code: [
                    { required: true, message: '请输入设备编码', trigger: 'blur' }
                ],
                xinghao: [
                    { required: true, message: '请输入型号', trigger: 'blur' }
                ],
                buyDate: [
                    { required: true, message: '请输入购买日期', trigger: 'blur' }
                ],
                usename: [
                    { required: true, message: '请输入经办人', trigger: 'blur' }
                ],
                pinpai: [
                    { required: true, message: '请输入设备品牌', trigger: 'blur' }
                ],
                allmoney: [
                    { required: true, message: '请输入设备总金额', trigger: 'blur' }
                ],
                counts: [
                    { required: true, message: '请输入设备数量', trigger: 'blur' }
                ],
                money: [
                    { required: true, message: '请输入设备单价', trigger: 'blur' }
                ],
                type: [
                    { required: true, message: '请输入设备类型', trigger: 'blur' }
                ],
                addr: [
                    { required: true, message: '请输入存放位置', trigger: 'blur' }
                ],
                supplier: [
                    { required: true, message: '请输入设备购买厂家', trigger: 'blur' }
                ],
                haveHouse: [
                    { required: true, message: '请输入所属车间', trigger: 'blur' }
                ],
                repairType: [
                    { required: true, message: '请输入维修保养类型', trigger: 'blur' }
                ],
                deviceNumber: [
                    { required: true, message: '请输入设备编号', trigger: 'blur' }
                ],
                deviceName: [
                    { required: true, message: '请输入设备名称', trigger: 'blur' }
                ],
                deviceModel: [
                    { required: true, message: '请输入设备型号', trigger: 'blur' }
                ],
                workshop: [
                    { required: true, message: '请输入所属车间', trigger: 'blur' }
                ],
                useDepartment: [
                    { required: true, message: '请输入使用部门', trigger: 'blur' }
                ],
                applicant: [
                    { required: true, message: '请输入检修申请人', trigger: 'blur' }
                ],
                faultProblem: [
                    { required: true, message: '请输入故障问题', trigger: 'blur' }
                ],
                faultCategory: [
                    { required: true, message: '请输入故障类别', trigger: 'blur' }
                ],
                maintenanceContent: [
                    { required: true, message: '请输入维修/保养内容', trigger: 'blur' }
                ],
                inspectionContent: [
                    { required: true, message: '请输入点检内容', trigger: 'blur' }
                ],
                maintenanceAmount: [
                    { required: true, message: '请输入维修/保养金额', trigger: 'blur' }
                ],
                maintenanceTime: [
                    { required: true, message: '请输入维修/保养时间', trigger: 'blur' }
                ],
                maintenanceRecord: [
                    { required: true, message: '请输入维修保养记录', trigger: 'blur' }
                ],
                maintenancePerson: [
                    { required: true, message: '请输入维修/保养人', trigger: 'blur' }
                ],
                inspectionPerson: [
                    { required: true, message: '请输入点检人', trigger: 'blur' }
                ],
                acceptancePerson: [
                    { required: true, message: '请输入验收人', trigger: 'blur' }
                ],
                replacementParts: [
                    { required: true, message: '请输入更换配件', trigger: 'blur' }
                ],
                partsFee: [
                    { required: true, message: '请输入配件费', trigger: 'blur' }
                ],
                total: [
                    { required: true, message: '请输入合计', trigger: 'blur' }
                ],
                workshopManager: [
                    { required: true, message: '请输入车间主任', trigger: 'blur' }
                ],
                leader: [
                    { required: true, message: '请输入主管领导', trigger: 'blur' }
                ]
            },
        };
        
    },
     created() {

    },
    methods: {
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                name: null,
                delFlag: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null,
                code: null,
                pinpai: null,
                xinghao: null,
                guige: null,
                buyDate: null,
                addr: null,
                channeng: null,
                status: "0",
                haveHouse: null,
                fapiao: null,
                hetong: null,
                money: null,
                type: null,
                usename: null,
                baogao: null,
                counts: null,
                supplier: null,
                allmoney: null,
                shenheName: null,
            };
            this.resetForm("form");
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加设备";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids;
            getById(this.url.getById, id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改设备";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateAction(this.url.edit, this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.$emit('ok');
                        });
                    } else {
                        addAction(this.url.add, this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.$emit('ok');
                        });
                    }
                }
            });
        },
    }
};
</script>